package co.uniquindio.software.medisys.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import co.uniquindio.software.medisys.entidades.Cita;
import co.uniquindio.software.medisys.entidades.Paciente;
import co.uniquindio.software.medisys.entidades.Usuario;
import co.uniquindio.software.medisys.logica.GestorPaciente;
import co.uniquindio.software.medisys.logica.GestorUsuario;
import co.uniquindio.software.medisys.logica.gestorCitas;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class GUI_Cita extends JFrame implements ActionListener 
{
	private JLabel fechaLabel;
	private JButton guardarButton;
	private JLabel cedulalabel;
	private JTextField cedulaField;
	private JTextField horaField;
	private JTextField fechaField;
	private JLabel horaLabel;
	private InterfazPrincipal miIP;
	
	
	public GUI_Cita(InterfazPrincipal IP)
	{
		miIP = IP;
		getContentPane().setLayout(null);
		setTitle("Citas");
		{
			fechaLabel = new JLabel();
			getContentPane().add(fechaLabel);
			fechaLabel.setText("Fecha");
			fechaLabel.setBounds(191, 38, 39, 16);
		}
		{
			horaLabel = new JLabel();
			getContentPane().add(horaLabel);
			horaLabel.setText("Hora");
			horaLabel.setBounds(293, 38, 39, 16);
		}
		{
			fechaField = new JTextField();
			getContentPane().add(fechaField);
			fechaField.setBounds(191, 66, 67, 23);
		}
		{
			horaField = new JTextField();
			getContentPane().add(horaField);
			horaField.setBounds(293, 66, 67, 23);
		}
		{
			cedulaField = new JTextField();
			getContentPane().add(cedulaField);
			cedulaField.setBounds(17, 66, 90, 24);
		}
		{
			cedulalabel = new JLabel();
			getContentPane().add(cedulalabel);
			cedulalabel.setText("Cedula del paciente");
			cedulalabel.setBounds(17, 34, 120, 16);
		}
		{
			guardarButton = new JButton();
			getContentPane().add(guardarButton);
			guardarButton.setText("Almacenar Cita");
			guardarButton.setBounds(148, 175, 123, 23);
			guardarButton.addActionListener(this);
		}
		this.setSize(439, 271);
	}


	@Override
	public void actionPerformed(ActionEvent e)
	{
		
		
		if(e.getSource()== guardarButton)
		{
			//Se capturan los datos en pantalla y se crea un objeto paciente 
			//Con estos datos capturados
			//se valida que hayan ingresado los datos
			if(fechaField.getText().equals("") || horaField.getText().equals("") )  	
			{
		
			JOptionPane.showMessageDialog(this, "Debe diligenciar todos los campos");
			
			}else
				
				
			
				
			try{
				
			
				
			Cita mC = new Cita();
			mC.setFecha(fechaField.getText());
			mC.setHora(horaField.getText());
			
			GestorPaciente gP = new GestorPaciente();
			GestorUsuario gU = new GestorUsuario();
			
			Paciente p = gP.consultarPaciente(Integer.parseInt(cedulaField.getText()));
			
		
			mC.setPaciente(p);
			mC.setUsuario(miIP.getUsuarioLogueado());
			
			gestorCitas gC = new gestorCitas();
			gC.guardarCitas(mC);
			JOptionPane.showMessageDialog(this,"la Cita a sido agregada sastifactoriamente");
			}catch (Exception ex) {
				// TODO: handle exception
				JOptionPane.showMessageDialog(this,"El paciente no se encuentra en la base de datos");
			}
			}
	}
}
